﻿#if UNITY_EDITOR
using System.Collections.Generic;
using System.Reflection;
/// <summary>
/// 模拟Behaviour分类
/// </summary>
public enum enESF_SimulateBehaviourClassify
{
    /// <summary>
    /// MonoBehaviour
    /// </summary>
    MonoBehaviour,
    /// <summary>
    /// UIBehaviour
    /// </summary>
    UIBehaviour,
}
/// <summary>
/// 模拟Behaviour方法
/// </summary>
public class ESF_SimulateBehaviourMethod : AbsESF_TypeReflexCodeResolver
{
    /// <summary>
    /// 模拟名称
    /// </summary>
    public string simulateName { get; private set; }
    /// <summary>
    /// 模拟名称Key值
    /// </summary>
    public int simulateNameKey { get; private set; }
    /// <summary>
    /// 枚举名称
    /// </summary>
    public string enumName { get; private set; }
    /// <summary>
    /// 模拟Behaviour分类
    /// </summary>
    public enESF_SimulateBehaviourClassify simulateBehaviourClassify { get; private set; }
    /// <summary>
    /// 是否生成模拟
    /// </summary>
    public bool isBuildSimulate { get; private set; }
    /// <summary>
    /// 方法信息
    /// </summary>
    public MethodInfo methodInfo { get; private set; }
    /// <summary>
    /// 方法形参参数组
    /// </summary>
    public List<string> methodFormalParameters { get; private set; }
    /// <summary>
    /// 方法输入参数组
    /// </summary>
    public List<string> methodInputParameters { get; private set; }
    /// <summary>
    /// 方法形参参数注释组
    /// </summary>
    public List<string> methodSummaryParameters { get; private set; }
    /// <summary>
    /// 方法声明代码
    /// </summary>
    public string methodDeclareCode { get; private set; }
    /// <summary>
    /// 方法Interface接口声明代码
    /// </summary>
    public string methodInterfaceCode { get; private set; }
    /// <summary>
    /// 方法Interface接口返回代码
    /// </summary>
    public string methodInterfaceReturnCode { get; private set; }
    /// <summary>
    /// 类名
    /// </summary>
    public string className { get; private set; }

    public ESF_SimulateBehaviourMethod(PropertyInfo _property, enESF_SimulateBehaviourClassify _classify) : base(_property)
    {
    }

    public ESF_SimulateBehaviourMethod(FieldInfo _fieldInfo, enESF_SimulateBehaviourClassify _classify) : base(_fieldInfo)
    {
    }

    public ESF_SimulateBehaviourMethod(MethodInfo _method, enESF_SimulateBehaviourClassify _classify) : base(_method)
    {
        methodInfo = _method;
        simulateBehaviourClassify = _classify;
        bool hasObs = _method.HasObsoleteAttribute();
        ParameterInfo[] pams = _method.GetParameters();
        methodFormalParameters = new List<string>();
        methodInputParameters = new List<string>();
        methodSummaryParameters = new List<string>();
        List<string> sks = new List<string>();

        #region 方法前缀
        List<string> mps = new List<string>();
        mps.Add(accessKeyword);
        mps.Add(overrideKeyword);
        mps.Add(returnCode);
        #endregion

        sks.Add(mps.ESF_Join(enESF_SeparatorSymbol.Space));
        sks.Add(_method.Name);
        if (pams != null && pams.Length > 0)
        {
            foreach (ParameterInfo p in pams)
            {
                hasObs |= p.HasObsoleteAttribute();
                methodFormalParameters.Add(string.Format("{0} _{1}", p.ParameterType.Name, p.Name));
                methodInputParameters.Add(string.Format("_{0}", p.Name));
                sks.Add(p.ParameterType.Name + p.Name);
                methodSummaryParameters.Add($"/// <param name=\"_{p.Name}\">{p.ParameterType.Name}</param>");
            }
        }

        simulateName = sks.ESF_Join(enESF_SeparatorSymbol.Space);
        simulateNameKey = simulateName.ESF_UniqueHashCode();
        className = $"Simulate{_classify}_{_method.Name}_{simulateNameKey.ToString().ESF_OnlyCNUAndOtherReplaceU()}";
        isBuildSimulate = !hasObs;

        string prefix = string.Empty;
        switch (_classify)
        {
            case enESF_SimulateBehaviourClassify.MonoBehaviour:
                prefix = "Mono";
                break;
            case enESF_SimulateBehaviourClassify.UIBehaviour:
                prefix = "UI";
                break;
        }
        enumName = $"{prefix}_{_method.Name}";
        methodDeclareCode = $"{mps.ESF_Join(enESF_SeparatorSymbol.Space)} {_method.Name}({methodFormalParameters.ESF_Join(enESF_SeparatorSymbol.Comma)})";
        methodInterfaceCode = $"{returnCode} {_method.Name} ({methodFormalParameters.ESF_Join(enESF_SeparatorSymbol.Comma)})";
        methodInterfaceReturnCode = returnCode;
    }
}
#endif